package com.csc531.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.csc531.DataTypes.Note;
import com.csc531.views.NotesView;

/**
 * @author Javier Figueroa
 *
 */
public class NotesListAdapter extends BaseAdapter 
{	
	protected Context mContext;
	protected int _position = 0;
	protected ArrayList<Boolean> _mExpanded;
	private ArrayList<Note> _notes;

	public NotesListAdapter(Context context) 
	{
		mContext = context;
		_notes = new ArrayList<Note>();
		_mExpanded = new ArrayList<Boolean>();
	}

	public int getCount() 
	{
		return _notes.size();
	}

	public Object getItem(int position) 
	{
		return _notes.get(position);
	}

	public long getItemId(int position)
	{
		return position;
	}

	public void addNote(Note newNote) 
	{
		_notes.add(newNote);
	}

	public void createExpandedList() 
	{
		int sizeOfList = _notes.size();
		int i = 0;
		while( i < sizeOfList ) 
		{
			_mExpanded.add(false);
			i++;
		}
	}

	public View getView(int position, View convertView, ViewGroup parent) 
	{
		NotesView sv;

		Note note = (Note) _notes.get(position);
		if (convertView == null) {
			sv = new NotesView(mContext, note, _mExpanded.get(position));
		} else {
			sv = (NotesView)convertView;
			sv.setTitle(note);
			sv.setDialogue(note);
			sv.setExpanded(_mExpanded.get(position));
		}

		return sv;
	}

	public void toggle(int position) 
	{
		_mExpanded.set(position,!_mExpanded.get(position));
		notifyDataSetChanged();
	}

}
